<%@ page language="java" pageEncoding="utf-8"%>
<%@page import="com.farm.web.constant.FarmConstant"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib uri="/view/conf/farmtag.tld" prefix="PF"%>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<base href="<PF:basePath/>" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>索引项目初始化- <PF:ParameterValue key="config.sys.title" /></title>
<meta name="description"
	content='<PF:ParameterValue key="config.sys.mate.description"/>'>
<meta name="keywords"
	content='<PF:ParameterValue key="config.sys.mate.keywords"/>'>
<meta name="author"
	content='<PF:ParameterValue key="config.sys.mate.author"/>'>
<meta name="robots" content="index,follow">
<jsp:include page="../web-simple/atext/include-web.jsp"></jsp:include>
</head>
<body>
	<!-- /.carousel -->
	<div class="containerbox">
		<div class="container" style="min-height: 500px; margin-top: 50px;">
			<div style="margin-top: 8px;"></div>
			<div class="row">
				<div class="col-md-12">
					<div class="panel panel-default">
						<div class="panel-heading">操作面板</div>
						<div class="panel-body"
							style="text-align: center; font-size: 18px;">
							<span id="cnum">0</span>/<span id="mnum">0</span>:<span
								id="state">准备</span>
						</div>
						<div class="panel-body" id="cconsoles">
							<a class="btn btn-primary btn-block"
								href="javascript:runDomainInit('scindex/runPDomain.do');">1初始化-索引域&nbsp;&nbsp;&nbsp;&nbsp;</a>
							<!--  -->
							<a class="btn btn-primary  btn-block"
								href="javascript:runDomainInit('scindex/runSCapp.do');">2初始化-检索业务</a>
							<hr />
							<a class="btn btn-success  btn-block" href="scindex/list.do">返回</a>
						</div>
					</div>
				</div>
			</div>
		</div>
	</div>
	<script type="text/javascript">
		//执行异步服务
		function runDomainInit(url) {
			disabledAllButton();
			$.post(url, {}, function(flag) {
				var key = flag.skey;
				var clock = setInterval(function() {
					$.post('scindex/process.do', {
						'skey' : key
					}, function(flag) {
						var cnum = flag.state.cnum;
						$('#cnum').text(cnum);
						var mnum = flag.state.mnum;
						$('#mnum').text(mnum);
						var message = flag.state.message;
						$('#message').text(message);
						var state = flag.state.state;
						$('#state').text(state);
						if (state == 'error') {
							abledAllButton();
							clearInterval(clock);
							alert(message);
						}
						if (state == 'running') {
							$('#state').text("正在执行...");
						}
						if (state == 'finish') {
							$('#state').text("完成");
							clearInterval(clock);
							abledAllButton();
						}
					}, 'json');
				}, 1000);
			}, 'json');
		}
		//禁用按钮
		function disabledAllButton() {
			$('#cconsoles .btn-primary').addClass("disabled");
			$('#state').text("...");
			$('#cnum').text(0);
			$('#mnum').text(0);
		}
		//启用按钮
		function abledAllButton() {
			$('#cconsoles .btn-primary').removeClass("disabled");
		}
	</script>
</body>
</html>